"""
Button
======

As this example demonstrates, you can attach multiple listener functions to
the `button_clicked` event.
"""
from wxpita import *

f = SizedFrame [
    SizedPanel(sizerType='horizontal') [
        Button(name='playBtn', label='Play'),
        Button(name='stopBtn', label='Stop'),
    ],

    TextCtrl(name='log', style='te_multiline', expand=True, size=(300,240)),
]

@f.Init
def _():
    f.stopBtn.Enable(False)

@f.playBtn.button_clicked
@f.stopBtn.button_clicked
def _(evt):
    f.log.AppendText('You clicked on <%s>\n' % evt.EventObject.GetLabel())

@f.playBtn.button_clicked
def _(evt):
    f.stopBtn.Enable(True)

    if f.playBtn.GetLabel() == 'Play':
        f.playBtn.SetLabel('Pause')
    else:
        f.playBtn.SetLabel('Play')

@f.stopBtn.button_clicked
def _(evt):
    f.playBtn.SetLabel('Play')
    f.playBtn.SetFocus()
    f.stopBtn.Enable(False)

f.Show('Button Example', size='fit')
